package com.tonghl.juc.CAS_study.code;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created by tonghl
 * 当前值和预期值比较相等则交换
 */
public class CASDemo {

    public static void main(String[] args) {
        AtomicInteger atomicInteger=new AtomicInteger(5);

        boolean retValue1=atomicInteger.compareAndSet(5,2019);
        boolean retValue2=atomicInteger.compareAndSet(5,2020);

        System.out.println(retValue1);
        System.out.println(retValue2);

    }
}
